package io.sdph.documents;

import io.sdph.documents.dao.InvoiceManagerDAO;
import io.sdph.documents.exceptions.InvoiceException;
import io.sdph.documents.model.Invoice;
import io.sdph.documents.model.InvoiceType;
import io.sdph.documents.model.PaymentMethod;
import io.sdph.documents.model.Print;
import io.sdph.products.model.Product;
import io.sdph.userprofile.model.User;

import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Klasa odpowiedzialna za zarządzanie fakturami.
 * 
 * @author 
 * @since 0.0.1
 */
@Service
public class InvoiceManager implements IInvoiceManager {
	
	private static Logger log = Logger.getLogger(InvoiceManager.class);
	
	@Autowired
	InvoiceManagerDAO managerDAO;

	@Override
    public List<Invoice> getInvoices(User user) {
        return managerDAO.getInvoices(user);
    }

    @Override
    public Invoice getInvoice(String number) {
        return managerDAO.getInvoice(number);
    }

    @Override
    public Byte[] generatePDF(Invoice invoice) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void printInvoice(Invoice invoice) {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(new Print(invoice));

        if (job.printDialog()) {
            try {
                job.print();
            } catch (PrinterException e) {
            }
        }
    }

	@Override
	public void saveInvoice(Invoice invoice) {
		managerDAO.saveInvoice(invoice);
	}
}
